<html xmlns:th="http://www.thymeleaf.org" lang="en">
<head>
    <meta charset="UTF-8">
    <title>登陆-在线聊天室</title>
    <style>
        * {
            margin: 0;
            padding: 0;
        }

        html {
            height: 100%;
        }

        body {
            height: 100%;
        }

        .container {
            height: 100%;
            background-image: linear-gradient(to right, #a6c1ee, #001112);
        }

        .login-wrapper {
            background-color: #117888;
            width: 320px;
            height: 400px;
            border-radius: 15px;
            padding: 0 50px;
            position: relative;
            left: 50%;
            top: 50%;
            transform: translate(-50%, -50%);
        }

        .header {
            font-size: 38px;
            font-weight: bold;
            text-align: center;
            line-height: 140px;
            color: black;
        }

        .input-item {
            display: block;
            width: 100%;
            margin-bottom: 20px;
            border: 1px solid white;
            padding: 10px;
            font-size: 15px;
            outline: none;
        }

        .input-item::placeholder {
            text-transform: uppercase;
        }

        .btn {
            border: 0;
            text-align: center;
            padding: 10px;
            width: 100%;
            margin-top: 30px;
            background-image: linear-gradient(to right, #a6c1ee, #007bff);
            color: #fff;
        }

        .input-item:focus {
            border: 1px solid #f30645;
        }

        .btn:hover {
            opacity: 0.8;
            cursor: pointer;
        }

        .msg {
            color: red;
        }
    </style>
</head>
<body>
<div class="container">
    <div class="login-wrapper">
        <div class="header">登&nbsp;&nbsp;陆</div>
        <div class="form-wrapper">
            <form method="post" action="login">
                <input type="text" name="username" value="zhangsan" placeholder="用户名" class="input-item">
                <input type="password" name="password" value="123456" placeholder="密码" class="input-item">
                <span class="msg">&nbsp;&nbsp;</span>
                <button type="button" class="btn" id="login">登陆</button>
            </form>
        </div>
    </div>
</div>
<script src="js/jquery.min.js"></script>
<script>
    $(function () {
        $("#login").click(function () {
            var username = $("input[name='username']");
            var password = $("input[name='password']");
            var msg = $(".msg");

            if (username.val() == "") {
                msg.text("用户名不能为空！");
                username.focus();
            } else if (password.val() == "") {
                msg.text("密码不能为空！");
                password.focus();
            } else {
                msg.html('&nbsp;&nbsp;')
                let formData = {username: username.val(), password: password.val()}
                console.log(formData)
                $.post('login', formData, function(res){
                    if(res.code != 200){
                        msg.text(res.message)
                    }else{
                        window.location.href="chat"
                    }
                })
            }

        })
    })
</script>
</body>
</html>
